home *** CD-ROM | disk | FTP | other *** search
/ Mac Format 1994 October / Macformat17.cdr / Shareware City / Developers / shutdown-fx-20-c / sfx init ƒ / code ƒ / sfx meat.c < prev    next >
Text File  |  1994-07-11  |  4KB  |  139 lines

  1. /**********************************************************************\
  2.  
  3. File:        sfx meat.c
  4.  
  5. Purpose:    This module handles the fade modules folder: setting up
  6.             the two lists based on the initial information, setting
  7.             information of fades.
  8.  
  9. This program is free software; you can redistribute it and/or modify
  10. it under the terms of the GNU General Public License as published by
  11. the Free Software Foundation; either version 2 of the License, or
  12. (at your option) any later version.
  13.  
  14. This program is distributed in the hope that it will be useful,
  15. but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17. GNU General Public License for more details.
  18.  
  19. You should have received a copy of the GNU General Public License
  20. along with this program in a file named "GNU General Public License".
  21. If not, write to the Free Software Foundation, 675 Mass Ave,
  22. Cambridge, MA 02139, USA.
  23.  
  24. \**********************************************************************/
  25.  
  26. #include "Folders.h"
  27. #include "sfx meat.h"
  28. #include "program globals.h"
  29.  
  30. static    long            gModuleDirID;
  31. static    short            gModuleVRefNum;
  32.  
  33. short HowManyModulesInstalledQQ(short *theAnswer, short *theOtherAnswer)
  34. /* return value is error code; number of installed modules passed back in *theAnswer */
  35. {
  36.     CInfoPBRec        pb;
  37.     OSErr            isHuman;
  38.     Str255            theName;
  39.     long            systemDirID;
  40.     short            i;
  41.     short            numModulesInstalled;
  42.     short            numModules;
  43.     
  44.     isHuman=FindFolder(kOnSystemDisk, kSystemFolderType, kDontCreateFolder, &gModuleVRefNum,
  45.                 &systemDirID);                    /* find system folder */
  46.     if (isHuman!=noErr)
  47.         return kCantFindSystemFolder;
  48.     
  49.     pb.dirInfo.ioCompletion=0L;
  50.     pb.dirInfo.ioNamePtr=MODULE_FOLDER;
  51.     pb.dirInfo.ioVRefNum=gModuleVRefNum;
  52.     pb.dirInfo.ioFDirIndex=0;             /* very important */
  53.     pb.dirInfo.ioDrDirID=systemDirID;
  54.     isHuman=PBGetCatInfo(&pb, FALSE);    /* get info on "MSG Fades ƒ" folder */
  55.     if (isHuman!=noErr)
  56.         return kCantFindModuleFolder;
  57.     
  58.     gModuleDirID=pb.dirInfo.ioDrDirID;
  59.     numModules=pb.dirInfo.ioDrNmFls;
  60.     numModulesInstalled=0;
  61.     
  62.     for (i=1; i<=numModules; i++)
  63.     {
  64.         pb.hFileInfo.ioCompletion=0L;
  65.         pb.hFileInfo.ioNamePtr=theName;
  66.         pb.hFileInfo.ioVRefNum=gModuleVRefNum;
  67.         pb.hFileInfo.ioFDirIndex=i;
  68.         pb.hFileInfo.ioDirID=gModuleDirID;
  69.         isHuman=PBGetCatInfo(&pb, FALSE);
  70.         if ((isHuman==noErr) && (!(pb.hFileInfo.ioFlAttrib&0x10)) &&
  71.             (pb.hFileInfo.ioFlFndrInfo.fdCreator==CREATOR))
  72.         {
  73.             /* got a fade module, now find out if it's used or unused */
  74.             
  75.             if (pb.hFileInfo.ioFlFndrInfo.fdType==USED_TYPE)
  76.             {
  77.                 numModulesInstalled++;
  78.             }
  79.         }
  80.     }
  81.     
  82.     *theAnswer=numModulesInstalled;
  83.     *theOtherAnswer=numModules;
  84.     
  85.     return 0;
  86. }
  87.  
  88. short GetAModule(short *index, Str255 theName, short *vRefNum, long *dirID)
  89. /* return value is error code; module info is passed back in params */
  90. {
  91.     CInfoPBRec        pb;
  92.     OSErr            isHuman;
  93.     short            i;
  94.     short            numModules;
  95.     short            numModulesInstalled;
  96.     short            resultCode;
  97.     short            ourModuleIndex;
  98.     unsigned long    dummy;
  99.     
  100.     if ((resultCode=HowManyModulesInstalledQQ(&numModulesInstalled, &numModules))!=0)
  101.         return resultCode;
  102.     
  103.     if (numModules==0)
  104.         return kNoModulesInFolder;
  105.     
  106.     if (numModulesInstalled==0)
  107.         return kNoModulesInstalled;
  108.     
  109.     GetDateTime(&dummy);
  110.     ourModuleIndex=1+((dummy&0x7fffffff)%numModulesInstalled);
  111.     
  112.     for (i=1; ((i<=numModules) && (ourModuleIndex>0)); i++)
  113.     {
  114.         pb.hFileInfo.ioCompletion=0L;
  115.         pb.hFileInfo.ioNamePtr=theName;
  116.         pb.hFileInfo.ioVRefNum=gModuleVRefNum;
  117.         pb.hFileInfo.ioFDirIndex=i;
  118.         pb.hFileInfo.ioDirID=gModuleDirID;
  119.         isHuman=PBGetCatInfo(&pb, FALSE);
  120.         if ((isHuman==noErr) && (!(pb.hFileInfo.ioFlAttrib&0x10)) &&
  121.             (pb.hFileInfo.ioFlFndrInfo.fdCreator==CREATOR))
  122.         {
  123.             /* got a fade module, now find out if it's used or unused */
  124.             
  125.             if (pb.hFileInfo.ioFlFndrInfo.fdType==USED_TYPE)
  126.             {
  127.                 ourModuleIndex--;
  128.             }
  129.         }
  130.     }
  131.     
  132.     *index=i-1;
  133.     *vRefNum=gModuleVRefNum;
  134.     *dirID=gModuleDirID;
  135.     /* name is already in parameter from PBGetCatInfo call */
  136.     
  137.     return 0;
  138. }
  139.